package com.jt.config;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * @author: taoyi
 * @date: 2021/6/15 14:11
 * @version: 1.0
 * @explain: 自动填充配置类
 */
@Component
public class MyMetaObjectHandler implements MetaObjectHandler {

    // 新增时自动填充 ,created,updated
    @Override
    public void insertFill(MetaObject metaObject) {
        Date date = new Date();
        this.setFieldValByName("created",date,metaObject);
        this.setFieldValByName("updated",date,metaObject);
    }

    // 更新时自动填充, updated
    @Override
    public void updateFill(MetaObject metaObject) {
        Date date = new Date();
        this.setFieldValByName("updated",date,metaObject);
    }
}
